package io.renren.modules.repair.controller;

import io.renren.common.entity.CarTypeEntity;
import io.renren.modules.repair.entity.RepairVo;
import io.renren.modules.repair.entity.req.RepairDeleteReq;
import io.renren.modules.repair.entity.req.UserRepairListReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.repair.entity.RepairEntity;
import io.renren.modules.repair.service.RepairService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

import javax.validation.Valid;
import java.util.List;


/**
 * 
 *
 * @author LL
 * @email wdlyl@163.com
 * @date 2022-04-12 14:48:24
 */
@RestController
@Api(value = "检修信息", tags = { "检修信息" })
@RequestMapping("/repair")
public class RepairController {
    @Autowired
    private RepairService repairService;

    /**
     * 根据车主id查正在检修表，界面可沿用“我的车辆”，展示汽车型号、汽车牌号、商家名称、商家联系方式、预计完成时间、预计检修费用
     * @author zyzhao
     * @date 2022/4/17 16:38
     * @param req req
     * @return null
     */
    @ApiOperation(value = "根据车主id和其他参数返回检修信息")
    @PostMapping("/list")
    //@RequiresPermissions("car:record:list")
    public R list(@Valid @RequestBody UserRepairListReq req){
        PageUtils page = repairService.queryUserRepairList(req);

        return R.success(page);
    }


    /**
     * 单条维修的清单
     */
    @ApiOperation(value = "查询单条清单")
    @GetMapping("/info/{repairId}")
    //@RequiresPermissions("car:record:info")
    public R info(@ApiParam("清单id") @PathVariable("repairId") Integer repairId){
        RepairVo record = repairService.getRepairInfo(repairId);

        return R.success(record);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存一条维修记录")
    //@RequiresPermissions("car:record:save")
    public R save(@RequestBody RepairEntity record){
		repairService.save(record);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新一条维修记录")
    @PostMapping("/update")
    //@RequiresPermissions("car:record:update")
    public R update(@RequestBody RepairEntity record){
		repairService.updateById(record);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除维修记录")
    @PostMapping("/delete")
    //@RequiresPermissions("car:record:delete")
    public R delete(@RequestBody RepairDeleteReq req){
		repairService.deleteRepairByIds(req);

        return R.ok();
    }
    
    @ApiOperation("查询维修相关标签")
    @GetMapping("/list/dict/{pid}")
    public R listDict(@ApiParam("标签的pid") @PathVariable("pid")String pid){
        List<CarTypeEntity> repairLists = repairService.listRepaidDict(pid);
        return R.success(repairLists);
    }
    
    @ApiOperation("缴费")
    @GetMapping("/pay/{repairId}")
    public R pay(@ApiParam("维修清单id") @PathVariable("repairId")Integer repairId){
        return repairService.payRepair(repairId);
    }

}
